# -*- coding:utf-8 -*-

__author__='zhaoxp'

from pprint import pprint

'''
了解切割序列的方法
'''



if __name__=='__main__':
    #a='abcdefgh'
    a=['a','b','c','d','e','f','g','h']
    print('length of a is %d, a = %s'%(len(a),a))
    print('First four is a[:4] = %s'%a[:4])
    print('Last four is a[-4:] = %s'%a[-4:])
    print('Middle two is a[3:-3] = %s'%a[3:-3])
    print('Middle four is a[2:-2] = %s'%a[2:-2])
    print('-'*20)
    print('a[:] = %s'%a[:])
    print('a[:5] = %s'%a[:5])
    print('a[:-1] = %s'%a[:-1])
    print('a[4:] = %s'%a[4:])
    print('a[-3:] = %s'%a[-3:])
    print('a[2:5] = %s'%a[2:5])
    print('a[2:-1] = %s'%a[2:-1])
    print('a[-3:-1] = %s'%a[-3:-1])
    #print(' = %s'%)
    try:
        print('a[20] = %s'%a[20])
    except IndexError:
        print('IndexError a[20]')
